package com.platform.framework.serviceimpl.pub;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import com.platform.framework.dao.pub.TradeFlowMybatisDao;
import com.platform.framework.entity.pub.TradeFlow;
import com.platform.framework.serviceinf.pub.TradeFlowService;

@Service("tradeFlowService")
public class TradeFlowServiceImpl implements TradeFlowService{

	@Autowired
	private TradeFlowMybatisDao tradeFlowMybatisDao;

	@Override
	public List<TradeFlow> getTradeFlowByOrderId (String orderNo) {
		return tradeFlowMybatisDao.getTradeFlowByOrderId(orderNo);
	}

	@Override
	public TradeFlow getTradeFlowByOutTradeNo (TradeFlow tradeFlow) {
		return tradeFlowMybatisDao.getByOutTradeNo(tradeFlow).get(0);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void saveOrUpdate(TradeFlow tradeFlow) {
		if (tradeFlow != null && tradeFlow.getId() == null) {
			tradeFlow.setCreateDate(new Date());
			tradeFlowMybatisDao.save(tradeFlow);
		} else if (tradeFlow != null && tradeFlow.getId() != null) {
			tradeFlow.setLastUpdatedDate(new Date());
			tradeFlowMybatisDao.update(tradeFlow);
		}
	}
	
}

